// pages/cart/cart.js
import dov from '../../utils/dov.min'
const regeneratorRuntime = require('../../utils/runtime')
Page({

  /**
   * Page initial data
   */
  data: {
    //  购物车列表绑定的数据
    cartList: [],
    //  购物车内的数据
    goods_id: [1, 2, 3, 4, 5],
    //  选中的id数组
    check_id: [],
    //  激活的下标
    _index: [],
    //  购物车数量
    count: [14]
  },

  //  选中商品的点击事件
  check(e) {
    console.log(e.target.dataset.index);
    this.setData({
      _index: false
    })
  },
  //  点击添加的按钮操作
  add(e) {
    console.log(e.target.dataset.add);
    this.setData({

    })
  },
  /**
   * Lifecycle function--Called when page load
   */
  async onLoad(options) {
    var add_id = getApp().globalData.cart_id
    console.log(add_id);
    var goods_list1 = []
    var goods_id = [112, 135, 166, 114, 111]
    if (add_id != '') {
      goods_id.push(add_id)
    }
    console.log(goods_id);
    for (let i of goods_id) {
      var {
        data: res
      } = await dov.get(`goods/${i}`)
      if (res.meta.status !== 200) {
        wx.showToast({
          title: '获取商品失败',
        })
      }
      //  获取数据成功后的方法
      wx.showToast({
        title: '成功!',
      })
      goods_list1.push(res.data)
      // console.log(goods_list);
      this.setData({
        goods_list: goods_list1
      })
    }
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})